﻿Imports HMSLibrary

Public Class MasterWindow

    Private Sub MasterWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        If FormType = FormsList.None Then Me.Close()
        Dim UCObject As Object = Nothing
        If FormType = FormsList.CompanyInfo Then
            Dim CompanyInfoUCObject As New CompanyInfoControl
            CompanyInfoUCObject.Margin = New Thickness(10)
            ModuleNameRun.Text = HMSFormName.CompanyInfo
            MasterSidePanel.FindVisibility = Visibility.Collapsed
            MasterSidePanel.AddVisibility = Visibility.Collapsed
            MainStack.Children.Add(CompanyInfoUCObject)
            Exit Sub
        ElseIf FormType = FormsList.ItemsServices Then
            UCObject = New ItemsServiceControl
            ModuleNameRun.Text = HMSFormName.ItemsServices
        ElseIf FormType = FormsList.BillTemplate Then
            UCObject = New BillTemplatesControl
            ModuleNameRun.Text = HMSFormName.billTemplates
        ElseIf FormType = FormsList.Lookup Then
            UCObject = New LookupsControl
            ModuleNameRun.Text = HMSFormName.Lookups
        ElseIf FormType = FormsList.Vendor Then
            UCObject = New VendorsControl
            ModuleNameRun.Text = HMSFormName.Vendors
        ElseIf FormType = FormsList.Wards Then
            UCObject = New WardsControl
            ModuleNameRun.Text = HMSFormName.Wards
        ElseIf FormType = FormsList.Users Then
            UCObject = New UsersControl
            ModuleNameRun.Text = HMSFormName.UsersList
        ElseIf FormType = FormsList.Rooms Then
            UCObject = New RoomsControl
            ModuleNameRun.Text = HMSFormName.Rooms
        ElseIf FormType = FormsList.Doctors Then
            UCObject = New DoctorsControl
            ModuleNameRun.Text = HMSFormName.Doctors
            'ElseIf FormType = FormsList.Complaints Then
            '    UCObject = New ComplaintsControl
            '    ModuleNameRun.Text = HMSFormName.Complaints
        ElseIf FormType = FormsList.Departments Then
            UCObject = New DepartmentControl
            ModuleNameRun.Text = HMSFormName.Departments
        ElseIf FormType = FormsList.Banks Then
            UCObject = New BanksControl
            ModuleNameRun.Text = HMSFormName.Banks
        ElseIf FormType = FormsList.Employee Then
            UCObject = New EmployeesControl
            ModuleNameRun.Text = HMSFormName.Employee
        ElseIf FormType = FormsList.UserProfile Then
            UCObject = New UserProfileControl
            ModuleNameRun.Text = HMSFormName.UserProfile
        ElseIf FormType = FormsList.Medicines Then
            UCObject = New MedicinesControl
            ModuleNameRun.Text = HMSFormName.Medicines
        ElseIf FormType = FormsList.Findings Then
            UCObject = New FindingsControl
            ModuleNameRun.Text = HMSFormName.Findings
        ElseIf FormType = FormsList.Investigations Then
            UCObject = New InvestigationControl
            ModuleNameRun.Text = HMSFormName.Investigations
        ElseIf FormType = FormsList.PrescriptionTemplate Then
            UCObject = New PrescriptionTemplateControl
            ModuleNameRun.Text = HMSFormName.PrescriptionTemplate
        ElseIf FormType = FormsList.Problems Then
            UCObject = New ProblemsControl
            ModuleNameRun.Text = HMSFormName.Problems
        ElseIf FormType = FormsList.Diagnosis Then
            UCObject = New DiagnosisControl
            ModuleNameRun.Text = HMSFormName.Diagnosis
            'ElseIf FormType = FormsList.TreatmentProcedures Then
            '    UCObject = New TreatmentProceduresControl
            '    ModuleNameRun.Text = HMSFormName.TreatmentProcedures
        End If
        If UCObject Is Nothing Then Exit Sub
        UCObject.Margin = New Thickness(10)
        MainStack.Children.Add(UCObject)
        If AppCommon.loginInfo.IsSuperUser = False Then ApplyPermission()
    End Sub

    Private Sub ApplyPermission()
        If AppCommon.loginInfo.IsSuperUser = True Then
            If FormType = FormsList.CompanyInfo Then
                MasterSidePanel.SaveVisibility = Visibility.Visible
            Else
                MasterSidePanel.AddVisibility = Visibility.Visible
                MasterSidePanel.FindVisibility = Visibility.Visible
                MasterSidePanel.SaveVisibility = Visibility.Visible
            End If
            Exit Sub
        End If
        Dim mp As ModulePermissions
        mp = (From ml In AppCommon.loginInfo.ModulesList Where ml.Name = ModuleNameRun.Text Select ml).FirstOrDefault
        If mp.Add = False Then MasterSidePanel.AddVisibility = Visibility.Collapsed Else MasterSidePanel.AddVisibility = Visibility.Visible
        If mp.Edit = False Then MasterSidePanel.FindVisibility = Visibility.Collapsed Else MasterSidePanel.FindVisibility = Visibility.Visible
        If mp.Print = False Then MasterSidePanel.PrintVisibility = Visibility.Collapsed Else MasterSidePanel.PrintVisibility = Visibility.Visible
    End Sub

    Private Sub MainWindow_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseDown
        DragMove()
    End Sub

    Private Sub CloseButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CloseButton.Click
        Me.Close()
    End Sub

    Private Sub MinimizeButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MinimizeButton.Click
        Me.WindowState = Windows.WindowState.Minimized
    End Sub

    Public Property FormType As FormsList = FormsList.None

    Private Sub MasterSidePanel_AddButtonClickEvent() Handles MasterSidePanel.AddButtonClickEvent
        Dim childObject As Object
        childObject = MainStack.Children(0)
        childObject.AddNew()
    End Sub

    Private Sub MasterSidePanel_BackButtonClickEvent() Handles MasterSidePanel.BackButtonClickEvent
        ApplyPermission()
        MasterSidePanel.BackVisibility = Visibility.Collapsed
        Dim childObject As Object
        childObject = MainStack.Children(0)
        childObject.BackView()
    End Sub

    Private Sub MasterSidePanel_CancelButtonClickEvent() Handles MasterSidePanel.CancelButtonClickEvent
        Me.Close()
    End Sub

    Private Sub MasterSidePanel_FindButtonClickEvent() Handles MasterSidePanel.FindButtonClickEvent
        'Dim SearchWinObject As New SearchWindow
        'SearchWinObject.FormType = FormType
        'SearchWinObject.ConnectionString = 
        'SearchWinObject.ShowDialog()
        Dim childObject As Object
        childObject = MainStack.Children(0)
        childObject.FindData()
        MasterSidePanel.PrintVisibility = Visibility.Collapsed
        MasterSidePanel.AddVisibility = Visibility.Collapsed
        MasterSidePanel.SaveVisibility = Visibility.Collapsed
        MasterSidePanel.FindVisibility = Visibility.Collapsed
        MasterSidePanel.BackVisibility = Visibility.Visible
    End Sub

    Private Sub MasterSidePanel_SaveButtonClickEvent() Handles MasterSidePanel.SaveButtonClickEvent
        Dim childObject As Object
        childObject = MainStack.Children(0)
        childObject.SaveData()
    End Sub
End Class
